#include <stdio.h>
#include "graph.h" //请勿删除，否则检查不通过

void delNext(ArcNode **pre, ArcNode *node) {
    *pre = node -> nextarc;
    free(node);
}

bool del_vertex(ListGraph *G, VertexType v){
    v = locate_vertex(G, v);
    if(!~v) return false;
    while(G -> vertex[v].firstarc) {
        delNext(&(G -> vertex[v].firstarc), G -> vertex[v].firstarc);
        -- G -> arcnum;
    }
    for(int i=v;i<G->vexnum;i++)
        G -> vertex[i] = G -> vertex[i+1];
    G -> vexnum--;
    for(int i=0;i<G->vexnum;i++) {
        VNode *rt = G -> vertex + i;
        while(rt -> firstarc && rt -> firstarc -> adjvex == v) {
            delNext(&(rt -> firstarc), rt -> firstarc);
            -- G -> arcnum;
        }
        ArcNode *arc = rt -> firstarc;
        while(arc) {
            while(arc -> nextarc && arc -> nextarc -> adjvex == v) 
                delNext(&(arc -> nextarc), arc -> nextarc), -- G -> arcnum;
            arc = arc -> nextarc;
        }
    }
    return true;
}
